package com.mrxu.monitor.constant;

import com.mrxu.monitor.config.MonitorProperties;
import com.mrxu.monitor.util.MonitorSpringUtils;
import org.springframework.util.StringUtils;

public class RedisConstant {

    public static final String MONITOR_PREFIX = "monitor";

    public static final String STASTIC = "stastic";

    public static final String HTTPSTATUS = "status";

    public static final String BROWSER = "browser";

    public static final String EXCEPTION = "exception";

    public static final String COUNTRY = "country";

    public static final String PROVINCE = "province";

    public static final String CITY = "city";

    public static final String PATHTIME = "pathtime";

    public static final String PATHCOUNT = "pathcount";

    private RedisConstant(){}

    /**
     * 获取key
     * name之间以":"分隔并且prefix开头
     * @param name 拼接后缀
     * @return "prefix:name:xx:xx"
     */
    public static String getKey(String... name) {
        StringBuffer keybuf = new StringBuffer(MONITOR_PREFIX);
        MonitorProperties monitorProperties = MonitorSpringUtils.getBean(MonitorProperties.class);
        if(StringUtils.hasLength(monitorProperties.getProjectCode())){
            keybuf.append(":").append(monitorProperties.getProjectCode());
        }
        for (String pkey : name) {
            keybuf.append(":");
            keybuf.append(pkey);
        }
        return keybuf.toString();
    }
}
